package com.example.crawler.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * com.yylc.sisyphus.utils
 *
 * @author 白雨浓
 * date: 17-9-15 下午3:37
 * content:日期封装
 */
public class DateUtil {
    private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public synchronized static String toString(Date date) {
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        return format.format(date);
    }

    public synchronized static Date toDate(String date) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        return format.parse(date);
    }

    public static Date stampToDate(String s) {
        return new Date((new Long(s) * 1000));
    }

    public static String dateToStamp(Date date) {
        return String.valueOf((date.getTime() / 1000));
    }
}
